<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1 style="display: inline-block">核算成本数据采集</h1>
    <a th:href="@{/accountManage}" type="button" class="btn btn-success"
       style="text-align:center;vertical-align:middle;font-size:30px;position:absolute;right:3%;display: inline-block;background-color: transparent;border: none;color: #5c5c5c;outline:none;">
        <i style="-moz-transform:scaleX(-1);-webkit-transform:scaleX(-1);-o-transform:scaleX(-1);transform:scaleX(-1);filter:FlipH;"
           class="glyphicon glyphicon-share-alt"></i><span
            style="margin-left: 5px;font-size: 16px;position: absolute;top: 20%;">返回</span>
    </a>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="row">
                        <div class="form-inline">
                            <div class="form-group">
                                <label class="control-label">
                                    项目编号：
                                </label>
                                <label class="control-label" th:text="${project.code}"></label>
                                <input id="code" type="hidden" th:value="${project.code}" style="display: none">
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    项目名称：
                                </label>
                                <label class="control-label" th:text="${project.name}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    需方：
                                </label>
                                <label class="control-label" th:text="${project.demander}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    安装地点：
                                </label>
                                <label class="control-label" th:text="${project.address}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    项目数量：
                                </label>
                                <label class="control-label" th:text="${project.num}"></label>
                            </div>
                            <div class="form-group">
                                <label class="control-label">
                                    设计类别：
                                </label>
                                <label class="control-label"
                                       th:text="${project.projectClassify == 1 ? '设计':'非设计'}"></label>
                            </div>
                        </div>
                    </div>
                    <form id="queryForm" style="display: none">
                        <input type="hide" name="batId" th:value="${batId}"/>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table-system"></table>
                    <table id="bootstrap-table-item"></table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>

<script th:inline="javascript">

    let systemTable, itemTable;
    $(function () {
        //加载系统类别表
        initSystemList();
        //加载成本项表
        initItemList();
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("halfAdjEditForm");
            js.reset("halfAdjEditForm");
        });
        /**
         * 获取数据
         */
        $("#btn_getData").click(function () {
            js.post({
                url: ctx + 'getData/getMatData',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {},
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(systemTable);
                        js.table.refresh(itemTable);
                    } else {
                        js.modal.warning(result.msg);
                    }
                },
                error: function () {
                    js.modal.fail();
                }

            });
        });
    });

    /**
     * 加载系统类别列表
     */
    function initSystemList() {
        systemTable = js.table.init({
            id: "bootstrap-table-system",
            url: ctx + "getData/accountingDataSourceList",
            showColumns: false,
            showExport: false,
            pagination: false,
            columns: [
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = systemTable.bootstrapTable('getOptions').pageSize;
                        var pageNumber = systemTable.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {title: '数据来源', field: 'source',width: '200'},
                {title: '数据名称', field: 'name'},
                // {title: '填报部门', field: 'dept',width: '300'},
                {
                    title: '获取状态', field: 'receiveStatus',width: '100',
                    formatter: function (value, row, index) {
                        if (value === 0) {
                            return '<span class="badge label-default">未获取</span>';
                        } else if (value === 1) {
                            return '<span class="badge label-success">已获取</span>';
                        }
                    }
                },
                {
                    title: '操作',width:'180',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if (hasP('ver:collection:aut')) {
                            elements.push('<button class="btn btn-success btn-xs" onclick="getDataBySystem(' + row.id + ')">数据获取</button>');
                        }
                        return elements.join('');
                    }
                }
            ]
        });
    }

    /**
     * 加载成本项类别列表
     */
    function initItemList() {

        itemTable = js.table.init({
            id: "bootstrap-table-item",
            url: ctx + "getData/accountingDataSourceListByItem",
            showColumns: false,
            showExport: false,
            pagination: false,                                   // 是否显示分页
            columns: [
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = itemTable.bootstrapTable('getOptions').pageSize;
                        var pageNumber = itemTable.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {title: '数据来源', field: 'source',width: '130'},
                {title: '专业', field: 'major',width: '70'},
                {title: '项目部分', field: 'part'},
                {title: '数据名称', field: 'name'},
                {title: '填报部门（填报人）', field: 'dept'},
                // {title: '填报人', field: 'staff'},
                // {title: '提交时间', field: 'addDate'},
                {
                    title: '获取状态', field: 'receiveStatus',width: '100',
                    formatter: function (value, row, index) {
                        if (value === 0) {
                            return '<span class="badge label-default">未获取</span>';
                        } else if (value === 1) {
                            return '<span class="badge label-success">已获取</span>';
                        } else {
                            return '';
                        }
                    }
                }, {
                    title: '数据状态', field: 'dataStatus',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<span class="badge label-warning">无数据</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-danger">不需要</span>';
                        } else if (value === 3) {
                            return '<span class="badge label-success">有数据</span>';
                        } else {
                            return '';
                        }
                    }
                },
                {title: '接收时间', field: 'receiveDate'},
                {
                    title: '操作', width: '180',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        // if (hasP('ver:collection:lab')) {
                        //     if (row.dataCode != 'ds002' && row.dataCode != 'ds003' && row.dataCode != 'ds004' && row.dataCode != 'ds005') {
                        //         elements.push('<button style="width: 48px" class="btn btn-success btn-xs" onclick="getData(' + row.id + ',' + row.batId + ')">获取</button>');
                        //     }
                        // }
                        if (hasP('ver:collection:view')) {
                            elements.push('<button style="width: 48px" class="btn btn-info btn-xs" onclick="viewInfo(' + row.id + ',' + row.batId + ')">查看</button>');
                        }
                        if (hasP('ver:collection:need')) {
                            elements.push('<button style="width: 48px" class="btn btn-danger btn-xs" onclick="updateDataStatus(' + row.id + ',2)">不需要</button>');
                            // elements.push('<button style="width: 48px" class="btn btn-warning btn-xs" onclick="updateDataStatus(' + row.id + ',1)">无数据</button>');
                        }
                        return elements.join('');
                    }
                }

            ]
        });
    }

    /**
     * 修改数据源状态
     * */
    function updateDataStatus(id, dataStatus) {
        let content;
        if (dataStatus === 1) {
            content = "不需要";
        } else if (dataStatus === 2) {
            content = "无数据";
        }
        js.confirmPost({
            content: "确定要把此类数据设置成" + content + "吗？",
            url: ctx + "getData/updateDataStatus",
            data: {
                id: id,
                dataStatus: dataStatus
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(itemTable);
                } else {
                    js.modal.warning(result.msg);
                    js.table.refresh(itemTable);
                }
            }
        });
    }


    /**
     * 从各个系统中获取数
     */
    function getDataBySystem(id) {
        js.post({
            url: ctx + 'getData/getDataBySystem',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: id
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(systemTable);
                    js.table.refresh(itemTable);
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }

        });
    }

    /**
     *去详细页查看
     */
    function viewInfo(dsId, batId) {
        let code = $("#code").val();
        location.href = ctx + "getData/gotoViewPage/" + dsId + "/" + batId + "/" + "/" + code;
    }


</script>
</body>
</html>